﻿namespace WMS6.SQLServerDAL
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Common;
    using System.Data.SqlClient;
    using WMS6.Common;
    using WMS6.DataEntity;
    using WMS6.DBUtility;
    using WMS6.IDAL;
    using WMS6.QueryEntity;

    public class ChargesDetailDA : IChargesDetailDA
    {
        private string CHARGE_AMOUNT = "@CHARGE_AMOUNT";
        private string CREATED_BY = "@CREATED_BY";
        private string EXECUTE_DATE = "@EXECUTE_DATE";
        private string IS_CHECKED = "@IS_CHECKED";
        private string ORDER_ID = "@ORDER_ID";
        private string ORDER_LINE_ID = "@ORDER_LINE_ID";
        private string OWNER_ID = "@OWNER_ID";
        private string QTY = "@QTY";
        private string RATE_UNIT = "@RATE_UNIT";
        private string SKU_ID = "@SKU_ID";
        private string SOURCE_TYPE = "@SOURCE_TYPE";
        private string SQL_CHECK_CHARGES_DETAIL_ID_UNIQUE = " SELECT COUNT(1) FROM @_@CHARGES_DETAIL WHERE ROWID = @ROWID ";
        private string SQL_DELETE_CHARGES_DETAIL = " DELETE FROM @_@CHARGES_DETAIL WHERE ROWID = @ROWID ";
        private string SQL_INSERT_CHARGES_DETAIL = " INSERT INTO @_@CHARGES_DETAIL ( WH_ID, EXECUTE_DATE, SKU_ID, OWNER_ID, ORDER_ID, ORDER_LINE_ID, TYPE, SOURCE_TYPE, CHARGE_AMOUNT, QTY, STATUS, IS_CHECKED, UDF1, UDF2, UDF3, UDF4, UDF5, UDF6, UDF7, UDF8, UDF9, UDF10, CREATED_BY, CREATED_DATE, UPDATED_BY, UPDATED_DATE, RATE_UNIT) VALUES ( @WH_ID, @EXECUTE_DATE, @SKU_ID, @OWNER_ID, @ORDER_ID, @ORDER_LINE_ID, @TYPE, @SOURCE_TYPE, @CHARGE_AMOUNT, @QTY, @STATUS, @IS_CHECKED, @UDF1, @UDF2, @UDF3, @UDF4, @UDF5, @UDF6, @UDF7, @UDF8, @UDF9, @UDF10, @CREATED_BY, GETDATE(), @UPDATED_BY, GETDATE(), @RATE_UNIT )  ";
        private string SQL_SELECT_ALL_CHARGES_DETAIL = " SELECT  ROWID, WH_ID, EXECUTE_DATE, SKU_ID, OWNER_ID, ORDER_ID, ORDER_LINE_ID, TYPE, SOURCE_TYPE, CHARGE_AMOUNT, QTY, STATUS, IS_CHECKED, UDF1, UDF2, UDF3, UDF4, UDF5, UDF6, UDF7, UDF8, UDF9, UDF10, CREATED_BY, CREATED_DATE, UPDATED_BY, UPDATED_DATE, RATE_UNIT  FROM  @_@CHARGES_DETAIL ";
        private string SQL_UPDATE_CHARGES_DETAIL = " UPDATE @_@CHARGES_DETAIL SET WH_ID = @WH_ID, SKU_ID = @SKU_ID, OWNER_ID = @OWNER_ID, ORDER_ID = @ORDER_ID, ORDER_LINE_ID = @ORDER_LINE_ID, TYPE = @TYPE, SOURCE_TYPE = @SOURCE_TYPE, CHARGE_AMOUNT = @CHARGE_AMOUNT, QTY = @QTY, STATUS = @STATUS, IS_CHECKED = @IS_CHECKED, UDF1 = @UDF1, UDF2 = @UDF2, UDF3 = @UDF3, UDF4 = @UDF4, UDF5 = @UDF5, UDF6 = @UDF6, UDF7 = @UDF7, UDF8 = @UDF8, UDF9 = @UDF9, UDF10 = @UDF10, UPDATED_BY = @UPDATED_BY, UPDATED_DATE = GETDATE(), RATE_UNIT = @RATE_UNIT WHERE ROWID = @ROWID  ";
        private string SQL_UPDATE_CHARGES_DETAIL_IS_CHECKED = " UPDATE @_@CHARGES_DETAIL SET IS_CHECKED = 'Y' WHERE ROWID = @ROWID ";
        private string STATUS = "@STATUS";
        private string TYPE = "@TYPE";
        private string UDF1 = "@UDF1";
        private string UDF10 = "@UDF10";
        private string UDF2 = "@UDF2";
        private string UDF3 = "@UDF3";
        private string UDF4 = "@UDF4";
        private string UDF5 = "@UDF5";
        private string UDF6 = "@UDF6";
        private string UDF7 = "@UDF7";
        private string UDF8 = "@UDF8";
        private string UDF9 = "@UDF9";
        private string UPDATED_BY = "@UPDATED_BY";
        private string WH_ID = "@WH_ID";

        public bool CheckChargesDetailIDUnique(string chargesDetailID, string execute_date, string whLoginID)
        {
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@ROWID", chargesDetailID), new SqlParameter("@EXECUTE_DATE", execute_date) };
            return (DBHelper.ExecuteScalar(CommandType.Text, this.SQL_CHECK_CHARGES_DETAIL_ID_UNIQUE.Replace("@_@", whLoginID), paras).ToString() == "1");
        }

        public bool CheckChargesDetailIDUnique(DataBase dataBase, DbTransaction tran, string chargesDetailID, string execute_date, string whLoginID)
        {
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@ROWID", chargesDetailID), new SqlParameter("@EXECUTE_DATE", execute_date) };
            return (dataBase.ExecuteScalar(tran, CommandType.Text, this.SQL_CHECK_CHARGES_DETAIL_ID_UNIQUE.Replace("@_@", whLoginID), paras).ToString() == "1");
        }

        public int DeleteChargesDetail(List<string> chargesDetailID, string execute_date, string whLoginID)
        {
            int result = 0;
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int j = 0; j < chargesDetailID.Count; j++)
                {
                    SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@ROWID", chargesDetailID[j]), new SqlParameter("@EXECUTE_DATE", execute_date) };
                    result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_DELETE_CHARGES_DETAIL.Replace("@_@", whLoginID), paras);
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int DeleteChargesDetail(DataBase dataBase, DbTransaction tran, List<string> chargesDetailID, string execute_date, string whLoginID)
        {
            int result = 0;
            try
            {
                for (int j = 0; j < chargesDetailID.Count; j++)
                {
                    SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@ROWID", chargesDetailID[j]), new SqlParameter("@EXECUTE_DATE", execute_date) };
                    result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_DELETE_CHARGES_DETAIL.Replace("@_@", whLoginID), paras);
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        public DataSet GetAllChargesDetail(string whLoginID)
        {
            string sql = this.SQL_SELECT_ALL_CHARGES_DETAIL.Replace("@_@", whLoginID);
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetAllChargesDetail(DataBase dataBase, DbTransaction tran, string whLoginID)
        {
            string sql = this.SQL_SELECT_ALL_CHARGES_DETAIL.Replace("@_@", whLoginID);
            return dataBase.ExecuteDataSet(tran, CommandType.Text, sql);
        }

        public ChargesDetailInfo GetChargesDetailByID(string chargesdetailID, string whLoginID)
        {
            string sql = this.SQL_SELECT_ALL_CHARGES_DETAIL.Replace("@_@", whLoginID) + " WHERE ROWID = @ROWID ";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@ROWID", chargesdetailID) };
            ChargesDetailInfo chargesDetailInfo = null;
            using (IDataReader reader = DBHelper.ExecuteReader(CommandType.Text, sql, paras))
            {
                if (reader.Read())
                {
                    DateTime CS00003;
                    chargesDetailInfo = new ChargesDetailInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), (reader["EXECUTE_DATE"].ToString() != "") ? DateTime.Parse(reader["EXECUTE_DATE"].ToString()) : (CS00003 = new DateTime()), reader["SKU_ID"].ToString(), reader["OWNER_ID"].ToString(), reader["ORDER_ID"].ToString(), (reader["ORDER_LINE_ID"].ToString() != "") ? int.Parse(reader["ORDER_LINE_ID"].ToString()) : 0, reader["TYPE"].ToString(), reader["SOURCE_TYPE"].ToString(), (reader["CHARGE_AMOUNT"].ToString() != "") ? decimal.Parse(reader["CHARGE_AMOUNT"].ToString()) : 0M, (reader["QTY"].ToString() != "") ? decimal.Parse(reader["QTY"].ToString()) : 0M, reader["STATUS"].ToString(), reader["IS_CHECKED"].ToString(), reader["UDF1"].ToString(), reader["UDF2"].ToString(), reader["UDF3"].ToString(), reader["UDF4"].ToString(), reader["UDF5"].ToString(), reader["UDF6"].ToString(), reader["UDF7"].ToString(), reader["UDF8"].ToString(), reader["UDF9"].ToString(), reader["UDF10"].ToString(), reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : (CS00003 = new DateTime()), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : new DateTime(), reader["RATE_UNIT"].ToString());
                }
            }
            return chargesDetailInfo;
        }

        public ChargesDetailInfo GetChargesDetailByID(DataBase dataBase, DbTransaction tran, string chargesdetailID, string whLoginID)
        {
            string sql = this.SQL_SELECT_ALL_CHARGES_DETAIL.Replace("@_@", whLoginID) + " WHERE ROWID = @ROWID ";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@ROWID", chargesdetailID) };
            ChargesDetailInfo chargesDetailInfo = null;
            IDataReader reader = dataBase.ExecuteReader(tran, CommandType.Text, sql, paras);
            if (reader.Read())
            {
                DateTime CS00003;
                chargesDetailInfo = new ChargesDetailInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), (reader["EXECUTE_DATE"].ToString() != "") ? DateTime.Parse(reader["EXECUTE_DATE"].ToString()) : (CS00003 = new DateTime()), reader["SKU_ID"].ToString(), reader["OWNER_ID"].ToString(), reader["ORDER_ID"].ToString(), (reader["ORDER_LINE_ID"].ToString() != "") ? int.Parse(reader["ORDER_LINE_ID"].ToString()) : 0, reader["TYPE"].ToString(), reader["SOURCE_TYPE"].ToString(), (reader["CHARGE_AMOUNT"].ToString() != "") ? decimal.Parse(reader["CHARGE_AMOUNT"].ToString()) : 0M, (reader["QTY"].ToString() != "") ? decimal.Parse(reader["QTY"].ToString()) : 0M, reader["STATUS"].ToString(), reader["IS_CHECKED"].ToString(), reader["UDF1"].ToString(), reader["UDF2"].ToString(), reader["UDF3"].ToString(), reader["UDF4"].ToString(), reader["UDF5"].ToString(), reader["UDF6"].ToString(), reader["UDF7"].ToString(), reader["UDF8"].ToString(), reader["UDF9"].ToString(), reader["UDF10"].ToString(), reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : (CS00003 = new DateTime()), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : new DateTime(), reader["RATE_UNIT"].ToString());
            }
            if (!reader.IsClosed)
            {
                reader.Close();
            }
            return chargesDetailInfo;
        }

        public List<ChargesDetailInfo> GetChargesDetailByID(DataBase dataBase, DbTransaction tran, List<string> sqlWhere, string UserID, string whLoginID)
        {
            string temp = this.SQL_SELECT_ALL_CHARGES_DETAIL.Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    temp = temp + " WHERE  IS_CHECKED !='Y' AND " + sqlWhere[i].ToString();
                }
                else
                {
                    temp = temp + " AND " + sqlWhere[i].ToString();
                }
            }
            List<ChargesDetailInfo> chargesDetailInfoList = new List<ChargesDetailInfo>();
            IDataReader reader = dataBase.ExecuteReader(tran, CommandType.Text, temp);
            while (reader.Read())
            {
                DateTime CS00002;
                ChargesDetailInfo chargesDetailInfo = new ChargesDetailInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), (reader["EXECUTE_DATE"].ToString() != "") ? DateTime.Parse(reader["EXECUTE_DATE"].ToString()) : (CS00002 = new DateTime()), reader["SKU_ID"].ToString(), reader["OWNER_ID"].ToString(), reader["ORDER_ID"].ToString(), (reader["ORDER_LINE_ID"].ToString() != "") ? int.Parse(reader["ORDER_LINE_ID"].ToString()) : 0, reader["TYPE"].ToString(), reader["SOURCE_TYPE"].ToString(), (reader["CHARGE_AMOUNT"].ToString() != "") ? decimal.Parse(reader["CHARGE_AMOUNT"].ToString()) : 0M, (reader["QTY"].ToString() != "") ? decimal.Parse(reader["QTY"].ToString()) : 0M, reader["STATUS"].ToString(), reader["IS_CHECKED"].ToString(), reader["UDF1"].ToString(), reader["UDF2"].ToString(), reader["UDF3"].ToString(), reader["UDF4"].ToString(), reader["UDF5"].ToString(), reader["UDF6"].ToString(), reader["UDF7"].ToString(), reader["UDF8"].ToString(), reader["UDF9"].ToString(), reader["UDF10"].ToString(), reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : (CS00002 = new DateTime()), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : (CS00002 = new DateTime()), reader["RATE_UNIT"].ToString());
                chargesDetailInfoList.Add(chargesDetailInfo);
            }
            if (!reader.IsClosed)
            {
                reader.Close();
            }
            return chargesDetailInfoList;
        }

        public DataSet GetChargesDetailByQueryList(List<string> sqlWhere, ChargesDetailQueryEntity chargesdetailQuery, string whLoginID)
        {
            string temp = this.SQL_SELECT_ALL_CHARGES_DETAIL.Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    temp = temp + " WHERE " + sqlWhere[i].ToString();
                }
                else
                {
                    temp = temp + " AND " + sqlWhere[i].ToString();
                }
            }
            if (!chargesdetailQuery.IsGetAll)
            {
                temp = PagingHelper.GetPagingSQL(temp, chargesdetailQuery.CurrentPage, chargesdetailQuery.PageSize, chargesdetailQuery.SortField, chargesdetailQuery.SortDirection);
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, temp);
        }

        public DataSet GetChargesDetailByQueryList(DataBase dataBase, DbTransaction tran, List<string> sqlWhere, ChargesDetailQueryEntity chargesdetailQuery, string whLoginID)
        {
            string temp = this.SQL_SELECT_ALL_CHARGES_DETAIL.Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    temp = temp + " WHERE " + sqlWhere[i].ToString();
                }
                else
                {
                    temp = temp + " AND " + sqlWhere[i].ToString();
                }
            }
            temp = PagingHelper.GetPagingSQL(temp, chargesdetailQuery.CurrentPage, chargesdetailQuery.PageSize, chargesdetailQuery.SortField, chargesdetailQuery.SortDirection);
            return dataBase.ExecuteDataSet(tran, CommandType.Text, temp);
        }

        public int InsertChargesDetail(ChargesDetailInfo chargesDetailInfo, string whLoginID)
        {
            int result = 0;
            DataBase db = new DataBase();
            DbConnection conn = db.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                chargesDetailInfo.WhID = whLoginID.Substring(0, whLoginID.Length - 1);
                SqlParameter[] paras = this.Set_ChargesDetail_Parameters(chargesDetailInfo);
                if (paras != null)
                {
                    result += db.ExecuteNonQuery(tran, CommandType.Text, this.SQL_INSERT_CHARGES_DETAIL.Replace("@_@", whLoginID), paras);
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int InsertChargesDetail(DataBase dataBase, DbTransaction tran, ChargesDetailInfo chargesDetailInfo, string whLoginID)
        {
            int result = 0;
            try
            {
                chargesDetailInfo.WhID = whLoginID.Substring(0, whLoginID.Length - 1);
                SqlParameter[] paras = this.Set_ChargesDetail_Parameters(chargesDetailInfo);
                if (paras != null)
                {
                    result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_INSERT_CHARGES_DETAIL.Replace("@_@", whLoginID), paras);
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        private SqlParameter[] Set_ChargesDetail_Parameters(ChargesDetailInfo chargesDetailInfo)
        {
            SqlParameter[] paramArray = new SqlParameter[] { 
                new SqlParameter(this.WH_ID, SqlDbType.VarChar, 30), new SqlParameter(this.EXECUTE_DATE, SqlDbType.DateTime, 8), new SqlParameter(this.SKU_ID, SqlDbType.VarChar, 50), new SqlParameter(this.OWNER_ID, SqlDbType.VarChar, 20), new SqlParameter(this.ORDER_ID, SqlDbType.VarChar, 20), new SqlParameter(this.ORDER_LINE_ID, SqlDbType.Int, 4), new SqlParameter(this.TYPE, SqlDbType.VarChar, 20), new SqlParameter(this.SOURCE_TYPE, SqlDbType.VarChar, 20), new SqlParameter(this.CHARGE_AMOUNT, SqlDbType.Decimal, 13), new SqlParameter(this.QTY, SqlDbType.Decimal, 13), new SqlParameter(this.STATUS, SqlDbType.VarChar, 20), new SqlParameter(this.IS_CHECKED, SqlDbType.VarChar, 1), new SqlParameter(this.UDF1, SqlDbType.VarChar, 30), new SqlParameter(this.UDF2, SqlDbType.VarChar, 30), new SqlParameter(this.UDF3, SqlDbType.VarChar, 30), new SqlParameter(this.UDF4, SqlDbType.VarChar, 30), 
                new SqlParameter(this.UDF5, SqlDbType.VarChar, 30), new SqlParameter(this.UDF6, SqlDbType.VarChar, 30), new SqlParameter(this.UDF7, SqlDbType.VarChar, 30), new SqlParameter(this.UDF8, SqlDbType.VarChar, 30), new SqlParameter(this.UDF9, SqlDbType.VarChar, 30), new SqlParameter(this.UDF10, SqlDbType.VarChar, 30), new SqlParameter(this.CREATED_BY, SqlDbType.VarChar, 20), new SqlParameter(this.UPDATED_BY, SqlDbType.VarChar, 20), new SqlParameter(this.RATE_UNIT, SqlDbType.VarChar, 20)
             };
            if (!string.IsNullOrEmpty(chargesDetailInfo.WhID))
            {
                paramArray[0].Value = chargesDetailInfo.WhID;
            }
            else
            {
                paramArray[0].Value = DBNull.Value;
            }
            paramArray[1].Value = chargesDetailInfo.ExecuteDate;
            paramArray[2].Value = chargesDetailInfo.SkuID;
            paramArray[3].Value = chargesDetailInfo.OwnerID;
            if (!string.IsNullOrEmpty(chargesDetailInfo.OrderID))
            {
                paramArray[4].Value = chargesDetailInfo.OrderID;
            }
            else
            {
                paramArray[4].Value = DBNull.Value;
            }
            paramArray[5].Value = chargesDetailInfo.OrderLineID;
            paramArray[6].Value = chargesDetailInfo.Type;
            if (!string.IsNullOrEmpty(chargesDetailInfo.SourceType))
            {
                paramArray[7].Value = chargesDetailInfo.SourceType;
            }
            else
            {
                paramArray[7].Value = DBNull.Value;
            }
            paramArray[8].Value = chargesDetailInfo.ChargeAmount;
            paramArray[9].Value = chargesDetailInfo.Qty;
            if (!string.IsNullOrEmpty(chargesDetailInfo.Status))
            {
                paramArray[10].Value = chargesDetailInfo.Status;
            }
            else
            {
                paramArray[10].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(chargesDetailInfo.IsChecked))
            {
                paramArray[11].Value = chargesDetailInfo.IsChecked;
            }
            else
            {
                paramArray[11].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(chargesDetailInfo.Udf1))
            {
                paramArray[12].Value = chargesDetailInfo.Udf1;
            }
            else
            {
                paramArray[12].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(chargesDetailInfo.Udf2))
            {
                paramArray[13].Value = chargesDetailInfo.Udf2;
            }
            else
            {
                paramArray[13].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(chargesDetailInfo.Udf3))
            {
                paramArray[14].Value = chargesDetailInfo.Udf3;
            }
            else
            {
                paramArray[14].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(chargesDetailInfo.Udf4))
            {
                paramArray[15].Value = chargesDetailInfo.Udf4;
            }
            else
            {
                paramArray[15].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(chargesDetailInfo.Udf5))
            {
                paramArray[0x10].Value = chargesDetailInfo.Udf5;
            }
            else
            {
                paramArray[0x10].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(chargesDetailInfo.Udf6))
            {
                paramArray[0x11].Value = chargesDetailInfo.Udf6;
            }
            else
            {
                paramArray[0x11].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(chargesDetailInfo.Udf7))
            {
                paramArray[0x12].Value = chargesDetailInfo.Udf7;
            }
            else
            {
                paramArray[0x12].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(chargesDetailInfo.Udf8))
            {
                paramArray[0x13].Value = chargesDetailInfo.Udf8;
            }
            else
            {
                paramArray[0x13].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(chargesDetailInfo.Udf9))
            {
                paramArray[20].Value = chargesDetailInfo.Udf9;
            }
            else
            {
                paramArray[20].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(chargesDetailInfo.Udf10))
            {
                paramArray[0x15].Value = chargesDetailInfo.Udf10;
            }
            else
            {
                paramArray[0x15].Value = DBNull.Value;
            }
            paramArray[0x16].Value = chargesDetailInfo.CreatedBy;
            paramArray[0x17].Value = chargesDetailInfo.UpdatedBy;
            paramArray[0x18].Value = chargesDetailInfo.RateUnit;
            return paramArray;
        }

        public int UpdateChargesDetail(ChargesDetailInfo chargesDetailInfo, string whLoginID)
        {
            int result = 0;
            DataBase db = new DataBase();
            DbConnection conn = db.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                chargesDetailInfo.WhID = whLoginID.Substring(0, whLoginID.Length - 1);
                SqlParameter[] paras = this.Set_ChargesDetail_Parameters(chargesDetailInfo);
                if (paras != null)
                {
                    result += db.ExecuteNonQuery(tran, CommandType.Text, this.SQL_UPDATE_CHARGES_DETAIL.Replace("@_@", whLoginID), paras);
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int UpdateChargesDetail(DataBase dataBase, DbTransaction tran, ChargesDetailInfo chargesDetailInfo, string whLoginID)
        {
            int result = 0;
            try
            {
                chargesDetailInfo.WhID = whLoginID.Substring(0, whLoginID.Length - 1);
                SqlParameter[] paras = this.Set_ChargesDetail_Parameters(chargesDetailInfo);
                if (paras != null)
                {
                    result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_UPDATE_CHARGES_DETAIL.Replace("@_@", whLoginID), paras);
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        public int UpdateChargesDetailIsChecked(DataBase dataBase, DbTransaction tran, int rowID, string whLoginID)
        {
            int result = 0;
            try
            {
                SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@ROWID", rowID) };
                if (paras != null)
                {
                    result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_UPDATE_CHARGES_DETAIL_IS_CHECKED.Replace("@_@", whLoginID), paras);
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }
    }
}

